package com.pclong.fightlandlordserver.game.model;

import com.pclong.fightlandlordserver.data.metadata.PlayerProfile;
import java.util.Date;
import java.util.UUID;

import org.apache.mina.core.session.IoSession;

/**
 *
 */
public class Player extends AbstractModel<Room, AbstractModel.DummyChildModel> {

    public static final String ATTR_NAME = "PLAYER";
    /** 玩家最后一次的游戏时间 */
    private long lastPlayTime = new Date().getTime();
    /** 玩家成功登录时间 */
    private long loginTime = new Date().getTime();
    /** 当前游戏id */
    private String gameId;
    /** 当前游戏玩家在游戏中的序号 */
    private int currentNumber;
    //上一句得分
    private int lastGameScore;
    //整个game得分统计，除非game解散了，否则累积
    private int totalGameScore;
    /** 玩家本局得分 */
    private double currentScore;
    /** 玩家本局所产生的系统分 */
    private double systemScore;
    // FIXME SJ 2009-11-10 积分板 追加 玩家当前总积分
    /** 玩家当前总积分 */
    private double playerCurrentScore;
    /** 当前玩家所对应的会话 */
    private IoSession iosession;
    /** 玩家初始状态，辅助程序运行，不参与业务，可忽略该字段 */
    private GameStatus orgStatus = GameStatus.RAW;
    /** 当前游戏状态 */
    private GameStatus currentStatus = GameStatus.WANDER;
    /** 是否为PUPPET */
    private boolean puppet = false;
    private PlayerProfile playerProfile;
    private boolean ready;
    private String avatar;
    private int pid;
    private String nickname;
    private String userId;
    private double score;
    private double money;
    private int pos;
    private String roomid;
    //玩家状态，0，大厅，1加入房间，2，已准备，3，游戏中4，
    private int state;

    /**
     * 
     */
    public Player() {
        super();
        this.id = UUID.randomUUID().toString();
        avatar = "../media/imageman.jpg";
    }

    /**
     * @return
     */
    public Room getCurrentRoom() {
        return this.parent;
    }

    /**
     * @return
     */
    public Lobby getCurrentLobby() {
        return this.parent.getParent();
    }

    /**
     * @return the orgStatus
     */
    public GameStatus getOrgStatus() {
        return orgStatus;
    }

    /**
     * @return the isGamePlaying
     */
    public GameStatus getCurrentStatus() {
        return currentStatus;
    }

    /**
     * FIXME This method should be moved to PuppetConsoleService.java
     * 
     * @return the isGamePlaying
     */
    public String getCurrentStatusLabel() {
        String result = "";
        switch (currentStatus) {
            case RAW:
                result = currentStatus.name() + "_原始状态，只是为辅助程序运行，不参与具体业务，可忽略";
                break;
            case WANDER:
                result = currentStatus.name() + "_未加入任何游戏房间，仍在徘徊中";
                break;
            case IDLE:
                result = currentStatus.name() + "_已加入游戏房间，未进入系统配对环节";
                break;
            case MATCHING:
                result = currentStatus.name() + "_已加入游戏房间，正在系统配对";
                break;
            case PLAYING:
                result = currentStatus.name() + "_游戏进行中";
                break;
        }
        return result;
    }

    /**
     * @param isGamePlaying the isGamePlaying to set
     */
    public void setCurrentStatus(GameStatus status) {
        if (this.currentStatus.equals(status)) {
            // 状态未发生改变时，不做任何处理
            return;
        }
        this.orgStatus = currentStatus;
        this.currentStatus = status;
        if (this.parent != null) {
            if (GameStatus.PLAYING.equals(status)) {
                // 状态从非游戏状态转入游戏状态
                this.lastPlayTime = new Date().getTime();
            }
            this.parent.updateGameStatusNumber(this);
        }
    }

    /**
     * @return
     */
    public long getLastPlayTime() {
        return this.lastPlayTime;
    }

    /**
     * @return the loginTime
     */
    public long getLoginTime() {
        return loginTime;
    }

    /**
     * @return the gameId
     */
    public String getGameId() {
        return gameId;
    }

    /**
     * @param gameId the gameId to set
     */
    public void setGameId(String gameId) {
        this.gameId = gameId;
    }

    /**
     * @return the iosession
     */
    public IoSession getIosession() {
        return iosession;
    }

    /**
     * @param iosession the iosession to set
     */
    public void setIosession(IoSession iosession) {
        this.iosession = iosession;
    }

    /**
     * @return the currentNumber
     */
    public String getCurrentNumber() {
        return String.valueOf(currentNumber);
    }

    /**
     * @param currentNumber the currentSn to set
     */
    public void setCurrentNumber(int currentNumber) {
        this.currentNumber = currentNumber;
    }

    /**
     * @return the currentScore
     */
    public double getCurrentScore() {
        return currentScore;
    }

    /**
     * @param currentScore the currentScore to set
     */
    public void setCurrentScore(double currentScore) {
        this.currentScore = currentScore;
    }

    /**
     * @return the systemScore
     */
    public double getSystemScore() {
        return systemScore;
    }

    /**
     * @param systemScore the systemScore to set
     */
    public void setSystemScore(double systemScore) {
        this.systemScore = systemScore;
    }

    /**
     * @return the playerCurrentScore
     */
    public double getPlayerCurrentScore() {
        return playerCurrentScore;
    }

    /**
     * @param playerCurrentScore the playerCurrentScore to set
     */
    public void setPlayerCurrentScore(double playerCurrentScore) {
        this.playerCurrentScore = playerCurrentScore;
    }

    /**
     * @return the puppet
     */
    public boolean isPuppet() {
        return puppet;
    }

    /**
     * @param puppet the puppet to set
     */
    public void setPuppet(boolean puppet) {
        this.puppet = puppet;
    }

    /**
     * @return the playerProfile
     */
    public PlayerProfile getPlayerProfile() {
        return playerProfile;
    }

    /**
     * @param playerProfile the playerProfile to set
     */
    public void setPlayerProfile(PlayerProfile playerProfile) {
        this.playerProfile = playerProfile;
    }

    /**
     * @return the ready
     */
    public boolean isReady() {
        return ready;
    }

    /**
     * @param ready the ready to set
     */
    public void setReady(boolean ready) {
        this.ready = ready;
    }

    /**
     * @return the avatar
     */
    public String getAvatar() {
        return avatar;
    }

    /**
     * @param avatar the avatar to set
     */
    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }

    /**
     * @return the pid
     */
    public int getPid() {
        return pid;
    }

    /**
     * @param pid the pid to set
     */
    public void setPid(int pid) {
        this.pid = pid;
    }

    /**
     * @return the nickname
     */
    public String getNickname() {
        return nickname;
    }

    /**
     * @param nickname the nickname to set
     */
    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    /**
     * @return the userId
     */
    public String getUserId() {
        return userId;
    }

    /**
     * @param userId the userId to set
     */
    public void setUserId(String userId) {
        this.userId = userId;
    }

    /**
     * @return the score
     */
    public double getScore() {
        return score;
    }

    /**
     * @param score the score to set
     */
    public void setScore(double score) {
        this.score = score;
    }

    /**
     * @return the money
     */
    public double getMoney() {
        return money;
    }

    /**
     * @param money the money to set
     */
    public void setMoney(double money) {
        this.money = money;
    }

    /**
     * @return the pos
     */
    public int getPos() {
        return pos;
    }

    /**
     * @param pos the pos to set
     */
    public void setPos(int pos) {
        this.pos = pos;
    }

    /**
     * @return the roomid
     */
    public String getRoomid() {
        return roomid;
    }

    /**
     * @param roomid the roomid to set
     */
    public void setRoomid(String roomid) {
        this.roomid = roomid;
    }

    /**
     * @return the state
     */
    public int getState() {
        return state;
    }

    /**
     * @param state the state to set
     */
    public void setState(int state) {
        this.state = state;
    }

    /**
     * @return the lastGameScore
     */
    public int getLastGameScore() {
        return lastGameScore;
    }

    /**
     * @param lastGameScore the lastGameScore to set
     */
    public void setLastGameScore(int lastGameScore) {
        this.lastGameScore = lastGameScore;
    }

    /**
     * @return the totalGameScore
     */
    public int getTotalGameScore() {
        return totalGameScore;
    }

    /**
     * @param totalGameScore the totalGameScore to set
     */
    public void setTotalGameScore(int totalGameScore) {
        this.totalGameScore = totalGameScore;
    }
}
